﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MinhTuan;

public partial class users_UpdateInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            String[] user = Session["user"].ToString().Split(',');
            int id = int.Parse(user[0]);
            if (id < 0)
            {
                Response.Redirect("http://localhost:2011/didong/users/dangnhap.html");
            }
            else {
                show(id);
                this.macapcha.Text = Access.MakeCapcha();
            }
        }
    }
    
    protected void btndangky_Click(object sender, EventArgs e)
    {
        if (string.Compare(this.macapcha.Text.ToLower(), txtcapcha.Text.ToLower(), true) == 0)
        {
            int Member_Id=int.Parse(hdid.Value.ToString());
            bool result=Members.UpdateMember(Member_Id,txthoten.Text,txtdiachi.Text,txtdienthoai.Text,txtemail.Text,txtthanhpho.Text);
            if (result == true)
            {
                Lthongbao.Text = "Cập nhật thành công";
            }
            else
            {
                Lthongbao.Text = "Cập nhật thất bại";
                macapcha.Text = Access.MakeCapcha();
            }
        }
        else
        {
            Lthongbao.Text = "Mã xác nhận không đúng";
            macapcha.Text = Access.MakeCapcha();
        }
    }
    protected void show(int id)
    {
        Members mymember = Members.GetMemberinfo(id);
        hdid.Value = mymember.Members_Id.ToString();
        txtdiachi.Text = mymember.Members_Address;
        txtdienthoai.Text = mymember.Members_Tel;
        txtemail.Text = mymember.Members_Mail;
        txtthanhpho.Text = mymember.Members_City;
        txttendangnhap.Text = mymember.Members_Login;
        txthoten.Text = mymember.Members_Name;
        

    }
}
